// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

var URLHelper = {};
URLHelper.prefixUrl = location.protocol + "//" + location.host + '/';

URLHelper.loginUrl = function() {
    return this.prefixUrl+'/user/userLog';
}

URLHelper.getPDFDataURL = function(branchId,typeId,dateStr) {
    return this.prefixUrl + 'getPdf?branchId=' + branchId + '&typeId=' + typeId + '&dateStr=' + dateStr;
}

URLHelper.getChargeData = function(branchId) {
    return this.prefixUrl + 'recharge/getAllCharge?branchId=' + branchId;
}

URLHelper.getOneSmsConfig = function(branchId) {
    return this.prefixUrl + 'surplus/getOne/' + branchId;
}

URLHelper.updateMSGLimit = function() {
    return this.prefixUrl + 'recharge/updateLimit' ;
}

URLHelper.toMSGLimit = function(branchId) {
    return this.prefixUrl + 'recharge/toUpdateLimit?branchId='+branchId;
}

URLHelper.toCustomerProject = function(branchId) {
    return this.prefixUrl + 'branchinfo/detailCustomerProject?branchId='+branchId;
}

URLHelper.toProject = function(projectId) {
    return this.prefixUrl + 'branchinfo/detailProject?projectId='+projectId;
}

URLHelper.toMatchMobile = function(projectId) {
    return this.prefixUrl + 'branchinfo/matchMobile?projectId='+projectId;
}

URLHelper.toSavePhone = function() {
    return this.prefixUrl + 'branchinfo/savePhone';
}

URLHelper.addCharge = function() {
    return this.prefixUrl + 'recharge/addCharge';
}

URLHelper.getPrice = function(branchId) {
    return this.prefixUrl + 'recharge/getPrice/' + branchId;
}

URLHelper.getSurplusData = function(branchId) {
    return this.prefixUrl + 'surplus/getAll?branchId=' + branchId;
}

URLHelper.getSurplusDataByC = function(branchId,count) {
    return this.prefixUrl + 'surplus/getAll?branchId=' + branchId + "&count=" + count;
}

URLHelper.surplusData = function() {
    return this.prefixUrl + 'surplus/getAll';
}

URLHelper.updateAlarmCount = function() {
    return this.prefixUrl + 'surplus/update';
}

URLHelper.emptyMoney = function() {
    return this.prefixUrl + 'surplus/emptyMoney';
}

URLHelper.getOneBranchReport = function(branchId, typeId, dateStr) {
    return this.prefixUrl + "report/getone?branchId="+branchId+"&typeId="+typeId+"&dateStr="+dateStr;
}

URLHelper.getAllBranchReport = function(branchId, typeId, dateStr) {
    return this.prefixUrl + 'report/allselect?branchId=' + branchId + '&typeId=' + typeId + '&dateStr=' + dateStr;
}

URLHelper.getBranchReport = function(branchId, typeId, dateStr) {
    return this.prefixUrl + 'report?branchId=' + branchId + '&typeId=' + typeId + '&dateStr=' + dateStr;
}

URLHelper.listExport = function(branchId,startDate,endDate,mobile,projectType) {
    return this.prefixUrl + '/listPdf?branchId='+branchId+'&startDate='+startDate+'&endDate='+endDate+'&mobile='+mobile+'&projectType='+projectType;
};

URLHelper.goMonitorCarUrl = function(branchId) {
    return this.prefixUrl + 'admin/car/monitor?branchId=' + branchId
};

URLHelper.monitorCarUrl = function(branchId, connectStatus) {
    return this.prefixUrl + 'admin/car/monitor/query?branchId=' + branchId +
        '&connectStatus=' + connectStatus + '&t=' + new Date().getTime();
};

URLHelper.monitorSystemUrl = function() {
    return this.prefixUrl + 'admin/system/monitor/query?t=' + new Date().getTime();
};

URLHelper.ajax = function(url, method, data, callback, errorFun) {
    var self = this;
    if (typeof url === 'string') {
        $.ajax({
            'url' : url,
            'method' : method,
            'dataType' : 'json',
            'data': data,
            'success': function(data) {
                $('.errStyle').remove();
                callback(data);
            },
            'complete': function(req) {
                if(req.status == 401) {
                    window.location.href = self.loginUrl();
                }
            },
            'error': errFun
        });
    } else if  (typeof  url === 'object') {
        if (!url['complete']) {
            url['complete'] = function(req) {if(req.status == 401) {  window.location.href = self.loginUrl() ;}}
        }
        url['error'] = errFun;
        var originFuc = url['success'];
        url['success'] = function(data) {
            $('.errStyle').remove();
            originFuc(data);
        }
        $.ajax(url);
    } else {
        alert('非法参数');
    }
}


function errFun(err) {
    var str = '';
    if(err.responseText != '') {
        str = '服务器发生了错误';
        console.log(err);
    } else {
        str = "网络连接异常";
    }
    notie.alert(3, str, 2);
}
